const Router = require('koa-router');
var qiniu = require('qiniu');
const router = new Router();
const checkToken = require('../middlewares/checkToken');

/**
 * 获取七牛云上传 token
 */
// checkToken.checkToken,
router.post('/getUploadKey', async (ctx) => {
    const accessKey = '402YZxjC6iLOTtsVn3OAedKy91Bjc6p11rVJfg6h';
    const secretKey = 'V4duV2LCuVPufV6ffqdCPuageC-DscmywGkSLLup';
    const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    const options = {
        scope: 'microblog',
    };
    const putPolicy = new qiniu.rs.PutPolicy(options);
    const uploadToken=putPolicy.uploadToken(mac);
    try {
        ctx.sendSucc(uploadToken);
    }catch (err) {
        ctx.sendError(err);
    }
} )

module.exports = router;
